import Vue from 'vue'

// 自定义权限指令设置
export default ({ store }): any => ({
  /**
   * 资源认证
   */
  auth: {
    bind(el, binding, vnode) {

      // 获取权限编码
      const authCode = binding.value.toString()
      // 验证权限码
      if (!authCode) {
        console.error('未传入权限')
        return
      }

      const hasAuth: boolean = (store.state.controlResource || []).findIndex(x => x.id === authCode) > -1

      // 验证权限
      if (!hasAuth) {
        el.style.display = 'none'
      }
    }
  }
})
